﻿using static CyberU;
using static CyberU.UI;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using System;
using System.IO;

public partial class CyberU
{
    public static bool ExistsDirectory(string path)
    {
        if (string.IsNullOrWhiteSpace(path))
            throw new ArgumentException("路径不能为空", nameof(path));

        return Directory.Exists(path);
    }

    public static void CreateDirectory(string path)
    {
        Directory.CreateDirectory(path);
    }

    public static void CreateDirectoryIfNotExists(string path)
    {
        if (string.IsNullOrWhiteSpace(path))
            throw new ArgumentException("路径不能为空", nameof(path));
        try
        {
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
                Delog($"已创建目录: {path}");
            }
        }
        catch (Exception ex)
        {
            Delog($"创建目录失败: {ex.Message}");
            // 或者使用日志框架如 Serilog、NLog 等记录日志
        }
    }

    public static string GetFileNameWithoutExtension(string path)
    {
        return System.IO.Path.GetFileNameWithoutExtension(path);
    }

    public static string GetDirectoryName(string path)
    {
        return System.IO.Path.GetDirectoryName(path);
    }

    public static string Combine(params string[] parts)
    {
        return System.IO.Path.Combine(parts);
    }

    public static string GetExtension(string path)
    {
        return System.IO.Path.GetExtension(path);
    }

    public static string Path2LocalUrl(string filePath)
    {
        return "file:///" + filePath.Replace("\\", "/");
    }
}